﻿$.extend(BMapLib.LuShu.prototype, {
	_hide: function() {
		this._overlay && this._map.removeOverlay(this._overlay);
		if (this._marker) {
			this._map.removeOverlay(this._marker);
			clearTimeout(this._timeoutFlag);
			this.stop();
		}
	}
});

function CommandCars(map) {
	this._map = map;
	this._cars = [];
	this._style = {
			"strokeColor" : "#F50CF2",
			"strokeWeight" : "2",
			"strokeOpacity" : "0.4",
			"strokeStyle" : "dashed",
			"icon" : new BMap.Icon('icons/toolbar/car.png', new BMap.Size(52,26),{anchor : new BMap.Size(27, 13)})
		};
}

$.extend(CommandCars.prototype, {
	"addCar" : function(code, path, speed) {
		var points = new Array();
		for (var j = 0; j < path.length; j++) {
			var position = path[j];
			points.push(new BMap.Point(position[0], position[1]));
		}
		var car = new BMapLib.LuShu(this._map, points, {
			defaultContent : "",
			autoView : false,
			icon : this._style.icon,
			speed : speed,
			landmarkPois: [],
			enableRotation : true
		});
		car.code = code;
		this._cars.push(car);
	},
	"start": function(code) {
		for (var i=0;i<this._cars.length;i++) {
			var car = this._cars[i];
			if (car.code == code) {
				car.start();				
			}
		}
	},
	"stop": function(code) {
		for (var i=0;i<this._cars.length;i++) {
			var car = this._cars[i];
			if (car.code == code) {
				car._hide();
			}
		}
	}
});
